import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'

// https://vite.dev/config/
export default defineConfig({
    plugins: [
        vue(),
    ],
    server: {
        proxy: {
            '/api': {
                target: 'http://localhost:8080',
                changeOrigin: true,
                ws: true,
            },
            // 保留旧的代理配置以备不时之需
            '/UserController': {
                target: 'http://localhost:8080/elm/api',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/UserController/, '/UserController')
            },
            '/BusinessController': {
                target: 'http://localhost:8080/elm/api',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/BusinessController/, '/BusinessController')
            },
            '/FoodController': {
                target: 'http://localhost:8080/elm/api',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/FoodController/, '/FoodController')
            },
            '/CartController': {
                target: 'http://localhost:8080/elm/api',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/CartController/, '/CartController')
            },
            '/OrdersController': {
                target: 'http://localhost:8080/elm/api',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/OrdersController/, '/OrdersController')
            },
            '/DeliveryAddressController': {
                target: 'http://localhost:8080/elm/api',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/DeliveryAddressController/, '/DeliveryAddressController')
            }
        }
    },
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        },
    },
})
